package com.guochenglang.www.web.result;

/**
 * 响应数据的封装
 *
 * @author 23217
 */
public class Result {
    /**
     * 执行成功返回成功数据
     *
     * @param obj 返回前端的数据
     * @return 返回结果
     */
    public static Result result(Object... obj) {
        return new Result("200", obj, "success");
    }

    /**
     * 执行失败返回执行失败结果
     *
     * @return 执行失败结果
     */
    public static Result noResult() {
        return new Result("500", null, "false");
    }

    /**
     * 含有敏感词返回敏感词结果
     *
     * @return 敏感词结果
     */
    public static Result dangerWord() {
        return new Result("200", null, "danger");
    }

    /**
     * 后台发生错误
     *
     * @param exception 错误信息
     * @return 执行结果
     */
    public static Result error(String exception){
        return new Result("500", null, exception);
    }

    /**
     * 响应码
     */
    private String code;
    /**
     * 响应信息
     */
    private String msg;
    /**
     * 响应数据
     */
    private Object data;

    public Result() {
    }

    public Result(String code, Object data, String msg) {
        this.code = code;
        this.data = data;
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    @Override
    public String toString() {
        return "Result{" +
                "code='" + code + '\'' +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}
